package com.edu.springboot.controller;

import com.edu.springboot.domain.Student;
import com.edu.springboot.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.w3c.dom.stylesheets.LinkStyle;

import java.util.List;

@CrossOrigin(value = "*",maxAge = 3600)
@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentService studentService;

    @GetMapping("/list")
    public List<Student> list()
    {
        return this.studentService.select();
    }

    @GetMapping("/getbyid/{stid}")
    public Student getById(@PathVariable("stid") Integer stid)
    {
        return  this.studentService.selectById(stid);
    }

    @GetMapping("/removebyid/{stid}")
    public String removeById(@PathVariable("stid") Integer stid)
    {
        this.studentService.deleteById(stid);
        return "OK";
    }

    @DeleteMapping("/removebyid2/{stid}")
    public String removeById2(@PathVariable("stid") Integer stid)
    {
        this.studentService.deleteById(stid);
        return "OK";
    }

    @PostMapping("/append")
    public String append(@RequestBody Student student)
    {
        this.studentService.insert(student);
        return "添加成功";
    }

    //put和post都能使用RequestBody
    @PutMapping("/updatebyid")
    public String modifyById(@RequestBody Student student)
    {
        this.studentService.updateById(student);
        return "修改成功";
    }
}
